package edu.msg.jthr.backend.bean;

import java.util.List;

import javax.ejb.EJB;
import javax.ejb.Stateless;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import edu.msg.jthr.backend.exception.ServiceException;
import edu.msg.jthr.backend.model.UserGroup;
import edu.msg.jthr.backend.repository.exception.RepositoryException;
import edu.msg.jthr.backend.repository.service.UserGroupRepository;
import edu.msg.jthr.backend.service.UserGroupService;
@Stateless (name = "UserGroupServiceBean", mappedName = "ejb/UserGroupService")
public class UserGroupServiceBean implements UserGroupService {

	@EJB
	private UserGroupRepository userGroupRepository;
	private static Logger LOG = LoggerFactory.getLogger(UserServiceBean.class);

	@Override
	public List<UserGroup> getAll() throws ServiceException {
		try {
			return userGroupRepository.getAll();
		} catch (RepositoryException e) {
			LOG.error("Get all user group failure!" + e.getMessage());
			throw new ServiceException("Get all user group failure!", e);
		}
	}

	@Override
	public UserGroup getById(Long id) throws ServiceException {
		try {
			return userGroupRepository.getById(id);
		} catch (RepositoryException e) {
			LOG.error("User group getById failure!" + e.getMessage());
			throw new ServiceException("User group getById failure!", e);
		}
	}

	@Override
	public void create(UserGroup obj) throws ServiceException {
		try {
			userGroupRepository.create(obj);
		} catch (RepositoryException e) {
			LOG.error("User group create failure!" + e.getMessage());
			throw new ServiceException("User group create failure!", e);
		}
	}

	@Override
	public void delete(UserGroup obj) throws ServiceException {
		try {
			userGroupRepository.create(obj);
		} catch (RepositoryException e) {
			LOG.error("User group delete failure!" + e.getMessage());
			throw new ServiceException("User group delete failure!", e);
		}
	}

	@Override
	public UserGroup update(UserGroup obj) throws ServiceException {
		try {
			return userGroupRepository.update(obj);
		} catch (RepositoryException e) {
			LOG.error("User group update failure!" + e.getMessage());
			throw new ServiceException("User group update failure!", e);
		}

	}

}
